```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java集合框架设计思想与架构</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .code-block {
            background: #2d2d2d;
            color: #f8f8f2;
            border-radius: 8px;
            position: relative;
        }
        .code-header {
            background: #1e1e1e;
            padding: 8px 16px;
            border-radius: 8px 8px 0 0;
            display: flex;
            align-items: center;
        }
        .code-lang {
            color: #ccc;
            font-size: 0.8rem;
            margin-left: 10px;
        }
        .code-dots {
            display: flex;
            margin-right: 12px;
        }
        .code-dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            margin-right: 6px;
        }
        .dot-red { background-color: #ff5f56; }
        .dot-yellow { background-color: #ffbd2e; }
        .dot-green { background-color: #27c93f; }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .concept-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            margin-bottom: 16px;
            font-size: 24px;
            color: white;
        }
        .section-divider {
            height: 4px;
            width: 80px;
            margin: 40px auto;
            background: linear-gradient(90deg, #6e8efb, #a777e3);
            border-radius: 2px;
        }
        .highlight-box {
            background: linear-gradient(135deg, rgba(110, 142, 251, 0.1) 0%, rgba(167, 119, 227, 0.1) 100%);
            border-left: 4px solid #6e8efb;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 md:py-32 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl text-center">
            <div class="inline-block px-4 py-2 bg-white bg-opacity-20 rounded-full mb-6">
                <span class="text-sm font-medium">Java集合框架深度解析</span>
            </div>
            <h1 class="text-4xl md:text-5xl font-bold mb-6 leading-tight">Java集合框架的设计思想与架构</h1>
            <p class="text-xl md:text-2xl font-light max-w-3xl mx-auto opacity-90 mb-10">探索集合接口的精妙设计、实现类的内部机制与性能优化之道</p>
            <div class="flex justify-center space-x-4">
                <a href="#core-concepts" class="px-6 py-3 bg-white text-indigo-600 font-medium rounded-full hover:bg-opacity-90 transition duration-300">
                    <i class="fas fa-brain mr-2"></i>核心概念
                </a>
                <a href="#implementations" class="px-6 py-3 bg-transparent border-2 border-white text-white font-medium rounded-full hover:bg-white hover:bg-opacity-10 transition duration-300">
                    <i class="fas fa-code mr-2"></i>实现解析
                </a>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="container mx-auto max-w-5xl px-4 md:px-0 py-16">
        <!-- Introduction -->
        <section class="mb-20">
            <div class="highlight-box p-6 rounded-lg mb-8">
                <h2 class="text-2xl font-bold text-indigo-800 mb-4"><i class="fas fa-lightbulb text-yellow-500 mr-2"></i>关键洞察</h2>
                <p class="text-gray-700">Java集合框架通过精妙的接口设计和多样化的实现类，提供了灵活、高效的集合操作方式。从基础的<code class="bg-indigo-100 text-indigo-800 px-2 py-1 rounded">Collection</code>接口到复杂的并发集合，每一层设计都体现了对性能、扩展性和易用性的平衡考虑。</p>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="concept-icon bg-indigo-500">
                                <i class="fas fa-project-diagram"></i>
                            </div>
                            <h3 class="text-xl font-bold ml-4">层次化接口设计</h3>
                        </div>
                        <p class="text-gray-600">集合框架采用清晰的接口继承结构，<code class="bg-gray-100 px-1 rounded">Collection</code>作为根接口，派生出<code class="bg-gray-100 px-1 rounded">List</code>、<code class="bg-gray-100 px-1 rounded">Set</code>、<code class="bg-gray-100 px-1 rounded">Queue</code>等子接口，每种接口都有特定的语义和约束。</p>
                    </div>
                </div>
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="concept-icon bg-purple-500">
                                <i class="fas fa-microchip"></i>
                            </div>
                            <h3 class="text-xl font-bold ml-4">多样化实现策略</h3>
                        </div>
                        <p class="text-gray-600">针对不同使用场景，框架提供多种数据结构实现：<code class="bg-gray-100 px-1 rounded">ArrayList</code>(数组)、<code class="bg-gray-100 px-1 rounded">LinkedList</code>(链表)、<code class="bg-gray-100 px-1 rounded">HashMap</code>(哈希表)等，各有其性能特点。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Core Concepts -->
        <section id="core-concepts" class="mb-20">
            <h2 class="text-3xl font-bold mb-8 text-center"><i class="fas fa-sitemap text-indigo-500 mr-3"></i>集合框架整体设计</h2>
            
            <div class="mb-12">
                <h3 class="text-xl font-semibold mb-4 text-gray-800">1. 接口层级结构</h3>
                <div class="bg-white rounded-lg shadow-sm p-6 mb-6">
                    <div class="mermaid mb-6">
                        graph TD
                            A[Iterable] --> B[Collection]
                            B --> C[List]
                            B --> D[Set]
                            B --> E[Queue]
                            F[Map]
                            C --> G[ArrayList]
                            C --> H[LinkedList]
                            D --> I[HashSet]
                            D --> J[TreeSet]
                            F --> K[HashMap]
                            F --> L[TreeMap]
                    </div>
                    <p class="text-gray-600">Java集合框架采用清晰的接口继承体系，<code class="bg-gray-100 px-1 rounded">Collection</code>作为集合类的根接口，<code class="bg-gray-100 px-1 rounded">Map</code>则独立存在。这种设计实现了接口与实现的分离，提高了灵活性。</p>
                </div>
            </div>

            <div class="mb-12">
                <h3 class="text-xl font-semibold mb-4 text-gray-800">2. 核心接口代码实现</h3>
                <div class="code-block mb-6">
                    <div class="code-header">
                        <div class="code-dots">
                            <div class="code-dot dot-red"></div>
                            <div class="code-dot dot-yellow"></div>
                            <div class="code-dot dot-green"></div>
                        </div>
                        <span class="code-lang">Java</span>
                    </div>
                    <pre class="p-4 overflow-x-auto"><code>// Collection接口是所有集合类的根接口
public interface Collection&lt;E&gt; extends Iterable&lt;E&gt; {
    boolean add(E e);
    boolean remove(Object o);
    int size();
    boolean isEmpty();
    void clear();
    Iterator&lt;E&gt; iterator();
}

// List接口继承自Collection，定义了有序集合
public interface List&lt;E&gt; extends Collection&lt;E&gt; {
    void add(int index, E element);
    E get(int index);
    E remove(int index);
    int indexOf(Object o);
}

// Map接口定义了键值对集合
public interface Map&lt;K, V&gt; {
    V get(Object key);
    V put(K key, V value);
    void clear();
    boolean containsKey(Object key);
}</code></pre>
                </div>
                <p class="text-gray-600">接口设计简洁而强大，定义了集合的基本操作契约。<code class="bg-gray-100 px-1 rounded">List</code>接口扩展了索引访问能力，<code class="bg-gray-100 px-1 rounded">Map</code>则专注于键值对操作。</p>
            </div>
        </section>

        <div class="section-divider"></div>

        <!-- Implementations -->
        <section id="implementations" class="mb-20">
            <h2 class="text-3xl font-bold mb-12 text-center"><i class="fas fa-code-branch text-purple-500 mr-3"></i>具体实现类与数据结构</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div>
                    <h3 class="text-xl font-semibold mb-4 text-gray-800">ArrayList 实现机制</h3>
                    <div class="code-block mb-6">
                        <div class="code-header">
                            <div class="code-dots">
                                <div class="code-dot dot-red"></div>
                                <div class="code-dot dot-yellow"></div>
                                <div class="code-dot dot-green"></div>
                            </div>
                            <span class="code-lang">Java</span>
                        </div>
                        <pre class="p-4 overflow-x-auto"><code>public class ArrayList&lt;E&gt; extends AbstractList&lt;E&gt; 
    implements List&lt;E&gt;, RandomAccess, Cloneable {
    
    private Object[] elementData;  // 存储元素的数组
    private int size;  // 当前集合的元素个数

    public boolean add(E e) {
        ensureCapacity(size + 1);  // 确保容量足够
        elementData[size++] = e;  // 添加元素并增加大小
        return true;
    }

    private void ensureCapacity(int minCapacity) {
        if (minCapacity > elementData.length) {
            grow(minCapacity);  // 扩容操作
        }
    }

    private void grow(int minCapacity) {
        int oldCapacity = elementData.length;
        int newCapacity = oldCapacity + (oldCapacity >> 1);  // 1.5倍扩容
        elementData = Arrays.copyOf(elementData, newCapacity);
    }
}</code></pre>
                    </div>
                    <div class="bg-blue-50 p-4 rounded-lg">
                        <h4 class="font-semibold text-blue-800 mb-2"><i class="fas fa-info-circle mr-2"></i>性能特点</h4>
                        <ul class="text-gray-600 list-disc pl-5">
                            <li>随机访问：O(1)</li>
                            <li>尾部插入：平均O(1)</li>
                            <li>中间插入/删除：O(n)</li>
                            <li>自动扩容策略：容量不足时按1.5倍增长</li>
                        </ul>
                    </div>
                </div>
                
                <div>
                    <h3 class="text-xl font-semibold mb-4 text-gray-800">HashMap 实现机制</h3>
                    <div class="code-block mb-6">
                        <div class="code-header">
                            <div class="code-dots">
                                <div class="code-dot dot-red"></div>
                                <div class="code-dot dot-yellow"></div>
                                <div class="code-dot dot-green"></div>
                            </div>
                            <span class="code-lang">Java</span>
                        </div>
                        <pre class="p-4 overflow-x-auto"><code>public class HashMap&lt;K,V&gt; extends AbstractMap&lt;K,V&gt; {
    static class Node&lt;K,V&gt; implements Map.Entry&lt;K,V&gt; {
        final int hash;
        final K key;
        V value;
        Node&lt;K,V&gt; next;  // 链表结构
        
        // 构造方法和接口实现...
    }

    transient Node&lt;K,V&gt;[] table;  // 哈希桶数组

    public V put(K key, V value) {
        int hash = hash(key);  // 计算哈希值
        int i = (n - 1) & hash;  // 计算数组下标
        
        // 处理哈希冲突...
        if (table[i] == null) {
            table[i] = newNode(hash, key, value, null);
        } else {
            // 遍历链表查找key...
        }
        
        // 扩容检查...
        if (++size > threshold)
            resize();
    }
}</code></pre>
                    </div>
                    <div class="bg-blue-50 p-4 rounded-lg">
                        <h4 class="font-semibold text-blue-800 mb-2"><i class="fas fa-info-circle mr-2"></i>实现要点</h4>
                        <ul class="text-gray-600 list-disc pl-5">
                            <li>数组+链表+红黑树(JDK8+)结构</li>
                            <li>默认负载因子0.75，平衡空间与时间效率</li>
                            <li>哈希冲突处理：链表法，超过阈值转为红黑树</li>
                            <li>扩容时容量翻倍，重新哈希</li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>

        <div class="section-divider"></div>

        <!-- Advanced Topics -->
        <section class="mb-20">
            <h2 class="text-3xl font-bold mb-12 text-center"><i class="fas fa-rocket text-indigo-500 mr-3"></i>高级主题与最佳实践</h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div>
                    <h3 class="text-xl font-semibold mb-4 text-gray-800">线程安全与并发集合</h3>
                    <div class="bg-white rounded-lg shadow-sm p-6">
                        <div class="mermaid mb-4">
                            graph LR
                                A[线程安全需求] --> B[同步包装]
                                A --> C[并发集合]
                                B --> D[Collections.synchronizedXXX]
                                C --> E[ConcurrentHashMap]
                                C --> F[CopyOnWriteArrayList]
                        </div>
                        <div class="code-block mt-4">
                            <div class="code-header">
                                <div class="code-dots">
                                    <div class="code-dot dot-red"></div>
                                    <div class="code-dot dot-yellow"></div>
                                    <div class="code-dot dot-green"></div>
                                </div>
                                <span class="code-lang">Java</span>
                            </div>
                            <pre class="p-4 overflow-x-auto"><code>// 使用ConcurrentHashMap实现线程安全
Map&lt;String, Integer&gt; map = new ConcurrentHashMap&lt;&gt;();

// 分段锁实现原理
public class ConcurrentHashMap&lt;K,V&gt; {
    final Segment&lt;K,V&gt;[] segments;
    
    public V get(Object key) {
        Segment&lt;K,V&gt; s = segmentFor(key);
        return s.get(key);
    }
    
    static final class Segment&lt;K,V&gt; extends ReentrantLock {
        volatile HashEntry&lt;K,V&gt;[] table;
        // 分段锁实现...
    }
}</code></pre>
                        </div>
                        <div class="mt-4 text-gray-600">
                            <p><span class="font-semibold">最佳实践：</span>优先使用<code class="bg-gray-100 px-1 rounded">ConcurrentHashMap</code>而非<code class="bg-gray-100 px-1 rounded">Hashtable</code>，在高并发场景下性能更优。</p>
                        </div>
                    </div>
                </div>
                
                <div>
                    <h3 class="text-xl font-semibold mb-4 text-gray-800">集合遍历与Stream API</h3>
                    <div class="bg-white rounded-lg shadow-sm p-6">
                        <div class="flex items-center mb-4">
                            <div class="bg-indigo-100 text-indigo-700 p-2 rounded-full mr-3">
                                <i class="fas fa-stream"></i>
                            </div>
                            <h4 class="font-bold">集合遍历方式演进</h4>
                        </div>
                        <ul class="space-y-3 mb-6">
                            <li class="flex items-start">
                                <span class="bg-indigo-100 text-indigo-700 text-xs font-bold px-2 py-1 rounded-full mr-2">1</span>
                                <span>传统for循环/迭代器</span>
                            </li>
                            <li class="flex items-start">
                                <span class="bg-indigo-100 text-indigo-700 text-xs font-bold px-2 py-1 rounded-full mr-2">2</span>
                                <span>增强for循环(foreach)</span>
                            </li>
                            <li class="flex items-start">
                                <span class="bg-indigo-100 text-indigo-700 text-xs font-bold px-2 py-1 rounded-full mr-2">3</span>
                                <span>Java 8 forEach方法</span>
                            </li>
                            <li class="flex items-start">
                                <span class="bg-indigo-100 text-indigo-700 text-xs font-bold px-2 py-1 rounded-full mr-2">4</span>
                                <span>Stream API(函数式)</span>
                            </li>
                        </ul>
                        
                        <div class="code-block">
                            <div class="code-header">
                                <div class="code-dots">
                                    <div class="code-dot dot-red"></div>
                                    <div class="code-dot dot-yellow"></div>
                                    <div class="code-dot dot-green"></div>
                                </div>
                                <span class="code-lang">Java</span>
                            </div>
                            <pre class="p-4 overflow-x-auto"><code>// Stream API示例
List&lt;String&gt; list = Arrays.asList("apple", "banana", "cherry");

// 过滤并转换
list.stream()
    .filter(s -> s.startsWith("a"))
    .map(String::toUpperCase)
    .forEach(System.out::println);

// 并行流处理
long count = list.parallelStream()
                .filter(s -> s.length() > 5)
                .count();</code></pre>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Summary -->
        <section class="bg-indigo-50 rounded-xl p-8 mb-16">
            <h3 class="text-2xl font-bold mb-6 text-indigo-800 text-center"><i class="fas fa-check-circle mr-2"></i>关键总结</h3>
            <div class="grid md:grid-cols-3 gap-6">
                <div class="bg-white p-5 rounded-lg shadow-sm">
                    <div class="text-indigo-500 text-3xl mb-3">
                        <i class="fas fa-layer-group"></i>
                    </div>
                    <h4 class="font-semibold mb-2">层次化设计</h4>
                    <p class="text-gray-600 text-sm">清晰的接口层级结构，实现与抽象分离，提供高度灵活性</p>
                </div>
                <div class="bg-white p-5 rounded-lg shadow-sm">
                    <div class="text-indigo-500 text-3xl mb-3">
                        <i class="fas fa-tachometer-alt"></i>
                    </div>
                    <h4 class="font-semibold mb-2">性能优化</h4>
                    <p class="text-gray-600 text-sm">针对不同场景选择最优数据结构，考虑时间/空间复杂度平衡</p>
                </div>
                <div class="bg-white p-5 rounded-lg shadow-sm">
                    <div class="text-indigo-500 text-3xl mb-3">
                        <i class="fas fa-users"></i>
                    </div>
                    <h4 class="font-semibold mb-2">并发安全</h4>
                    <p class="text-gray-600 text-sm">提供多种线程安全方案，从同步包装到高效的并发集合实现</p>
                </div>
            </div>
        </section>
    </div>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12">
        <div class="container mx-auto max-w-5xl px-4 md:px-0">
            <div class="flex flex-col items-center">
                <div class="text-2xl font-bold text-white mb-2">技术小馆</div>
                <div class="mb-4">探索编程艺术的深度与广度</div>
                <a href="http://www.yuque.com/jtostring" class="text-indigo-400 hover:text-indigo-300 transition duration-300">
                    <i class="fas fa-external-link-alt mr-2"></i>http://www.yuque.com/jtostring
                </a>
                <div class="mt-6 text-sm text-gray-500">
                    &copy; 2023 技术小馆. 保留所有权利.
                </div>
            </div>
        </div>
    </footer>

    <script>
        // Initialize Mermaid diagrams
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true
            }
        });
        
        // Smooth scrolling for anchor links
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });
    </script>
</body>
</html>
```